\hypertarget{class_socket}{\section{Socket类 参考}
\label{class_socket}\index{Socket@{Socket}}
}


Socket抽象基类  




{\ttfamily \#include $<$Socket.\+h$>$}

类 Socket 继承关系图\+:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[height=3.000000cm]{class_socket}
\end{center}
\end{figure}
\subsection*{Public 成员函数}
\begin{DoxyCompactItemize}
\item 
\hypertarget{class_socket_ad070af071d2e044ab71bad9a84360b57}{virtual sint32 {\bfseries open} ()=0}\label{class_socket_ad070af071d2e044ab71bad9a84360b57}

\item 
virtual sint32 \hyperlink{class_socket_ae648df0cc1da2ad17f4bc65d396d2b71}{bind} (uint16 local\+Port, std\+::string local\+Addr=\char`\"{}\char`\"{})
\begin{DoxyCompactList}\small\item\em 绑定socket到指定\+I\+P地址的端口上 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_socket_abfbea049b117c0f4c91405b31b4694e4}{connect\+To\+Host} (uint16 peer\+Port, std\+::string peer\+Addr)
\begin{DoxyCompactList}\small\item\em 检查socket是否已打开 \end{DoxyCompactList}\item 
\hypertarget{class_socket_aac11b26f96b7482cce8290d906a692b9}{std\+::string {\bfseries get\+Local\+Addr} ()}\label{class_socket_aac11b26f96b7482cce8290d906a692b9}

\item 
\hypertarget{class_socket_a89b9de5a3e5e81bf5fdcb94989565a72}{std\+::string {\bfseries get\+Peer\+Addr} ()}\label{class_socket_a89b9de5a3e5e81bf5fdcb94989565a72}

\item 
\hypertarget{class_socket_a8e4c158afc1b2cefc43609c1c0622088}{sint32 {\bfseries get\+Local\+Port} ()}\label{class_socket_a8e4c158afc1b2cefc43609c1c0622088}

\item 
\hypertarget{class_socket_ac75c2e8b397efe26f53b9ef541dee98f}{sint32 {\bfseries get\+Peer\+Port} ()}\label{class_socket_ac75c2e8b397efe26f53b9ef541dee98f}

\item 
bool \hyperlink{class_socket_aa9e3b0239157c8c1fb5a881b22f6e4cb}{is\+Alive} ()
\begin{DoxyCompactList}\small\item\em 检查socket是否已打开 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_socket_af9a5eeed90596d23629a4d7777696575}{open} (const char $\ast$device, sint32 io\+Mode)
\begin{DoxyCompactList}\small\item\em 打开设备 \end{DoxyCompactList}\item 
virtual sint32 \hyperlink{class_socket_a1fe4c90416cad39e96049019d178fb37}{close} ()
\begin{DoxyCompactList}\small\item\em 关闭socket \end{DoxyCompactList}\item 
\hypertarget{class_socket_a67433b892f199e1745e3c7ca14e59593}{virtual sint32 {\bfseries read\+Data} (char $\ast$buf, sint32 count, sint32 timeout\+Ms=-\/1)=0}\label{class_socket_a67433b892f199e1745e3c7ca14e59593}

\item 
\hypertarget{class_socket_a896381b2d1eeeccf5a602ac7b40f67e1}{virtual sint32 {\bfseries write\+Data} (const char $\ast$buf, sint32 count, sint32 timeout\+Ms=-\/1)=0}\label{class_socket_a896381b2d1eeeccf5a602ac7b40f67e1}

\item 
virtual sint32 \hyperlink{class_socket_ae40a3069ac1e266adb1c4e9575190d49}{set\+Attribute} (sint32 attr, sint32 value)
\begin{DoxyCompactList}\small\item\em 设置socket类型 \end{DoxyCompactList}\item 
\hypertarget{class_socket_afe297c65236efc74fdadb399f7081fc9}{virtual sint32 {\bfseries get\+Attribute} (sint32 attr)}\label{class_socket_afe297c65236efc74fdadb399f7081fc9}

\end{DoxyCompactItemize}
\subsection*{Protected 属性}
\begin{DoxyCompactItemize}
\item 
\hypertarget{class_socket_a58716b99c436fc5003aaf29aec0dfac6}{sint32 {\bfseries m\+\_\+sockfd}}\label{class_socket_a58716b99c436fc5003aaf29aec0dfac6}

\item 
\hypertarget{class_socket_ae4a66dcf9fec7da8a9b1b83856fe66be}{std\+::string {\bfseries m\+\_\+local\+Addr}}\label{class_socket_ae4a66dcf9fec7da8a9b1b83856fe66be}

\item 
\hypertarget{class_socket_a75ed54fdf1f77872e030720424d4ee1a}{std\+::string {\bfseries m\+\_\+peer\+Addr}}\label{class_socket_a75ed54fdf1f77872e030720424d4ee1a}

\item 
\hypertarget{class_socket_a16e04162da1d3f68516998af9e061999}{uint16 {\bfseries m\+\_\+local\+Port}}\label{class_socket_a16e04162da1d3f68516998af9e061999}

\item 
\hypertarget{class_socket_aba1561ea305405179f0b60a609248b97}{uint16 {\bfseries m\+\_\+peer\+Port}}\label{class_socket_aba1561ea305405179f0b60a609248b97}

\item 
\hypertarget{class_socket_a352e7e79cc7c18ab10fec2e4ccc51b1d}{struct sockaddr\+\_\+in {\bfseries m\+\_\+local\+Sock\+Addr}}\label{class_socket_a352e7e79cc7c18ab10fec2e4ccc51b1d}

\end{DoxyCompactItemize}


\subsection{详细描述}
Socket抽象基类 

\subsection{成员函数说明}
\hypertarget{class_socket_ae648df0cc1da2ad17f4bc65d396d2b71}{\index{Socket@{Socket}!bind@{bind}}
\index{bind@{bind}!Socket@{Socket}}
\subsubsection[{bind}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Socket\+::bind (
\begin{DoxyParamCaption}
\item[{uint16}]{local\+Port, }
\item[{std\+::string}]{local\+Addr = {\ttfamily \char`\"{}\char`\"{}}}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_socket_ae648df0cc1da2ad17f4bc65d396d2b71}


绑定socket到指定\+I\+P地址的端口上 


\begin{DoxyParams}{参数}
{\em local\+Port} & 要绑定的端口 \\
\hline
{\em local\+Addr} & 绑定的\+I\+P地址,不指定则为默认本机任意地址 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}
\hypertarget{class_socket_a1fe4c90416cad39e96049019d178fb37}{\index{Socket@{Socket}!close@{close}}
\index{close@{close}!Socket@{Socket}}
\subsubsection[{close}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Socket\+::close (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_socket_a1fe4c90416cad39e96049019d178fb37}


关闭socket 


\begin{DoxyParams}{参数}
{\em void} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


重载 \hyperlink{class_i_o_device_a1120c9e7a7c4d0b23083effbe4cb6279}{I\+O\+Device} .



被 \hyperlink{class_tcp_socket_a58d2fff73fb69eb3f18b00aca7d6c87a}{Tcp\+Socket} , 以及 \hyperlink{class_udp_socket_a579acf9700828b5e1c030b37475ec7ea}{Udp\+Socket} 重载.

\hypertarget{class_socket_abfbea049b117c0f4c91405b31b4694e4}{\index{Socket@{Socket}!connect\+To\+Host@{connect\+To\+Host}}
\index{connect\+To\+Host@{connect\+To\+Host}!Socket@{Socket}}
\subsubsection[{connect\+To\+Host}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Socket\+::connect\+To\+Host (
\begin{DoxyParamCaption}
\item[{uint16}]{peer\+Port, }
\item[{std\+::string}]{peer\+Addr}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_socket_abfbea049b117c0f4c91405b31b4694e4}


检查socket是否已打开 


\begin{DoxyParams}{参数}
{\em void} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
打开返回true,关闭返回false 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


被 \hyperlink{class_tcp_socket_a5470902009a68d3fd66c924eb33a6737}{Tcp\+Socket} 重载.

\hypertarget{class_socket_aa9e3b0239157c8c1fb5a881b22f6e4cb}{\index{Socket@{Socket}!is\+Alive@{is\+Alive}}
\index{is\+Alive@{is\+Alive}!Socket@{Socket}}
\subsubsection[{is\+Alive}]{\setlength{\rightskip}{0pt plus 5cm}bool Socket\+::is\+Alive (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{class_socket_aa9e3b0239157c8c1fb5a881b22f6e4cb}


检查socket是否已打开 


\begin{DoxyParams}{参数}
{\em void} & \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
打开返回true,关闭返回false 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}
\hypertarget{class_socket_af9a5eeed90596d23629a4d7777696575}{\index{Socket@{Socket}!open@{open}}
\index{open@{open}!Socket@{Socket}}
\subsubsection[{open}]{\setlength{\rightskip}{0pt plus 5cm}virtual sint32 Socket\+::open (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{dev\+Name, }
\item[{sint32}]{mode}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}}\label{class_socket_af9a5eeed90596d23629a4d7777696575}


打开设备 


\begin{DoxyParams}{参数}
{\em dev\+Name} & 设备全名(包含路径,如\+:/dev/tty\+S0) \\
\hline
{\em mode} & 打开模式\+I\+O\+\_\+\+M\+O\+D\+E\+\_\+\+E \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
设备打开成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


重载 \hyperlink{class_i_o_device_a426aac91300f077d57b1f30c76c7c430}{I\+O\+Device} .

\hypertarget{class_socket_ae40a3069ac1e266adb1c4e9575190d49}{\index{Socket@{Socket}!set\+Attribute@{set\+Attribute}}
\index{set\+Attribute@{set\+Attribute}!Socket@{Socket}}
\subsubsection[{set\+Attribute}]{\setlength{\rightskip}{0pt plus 5cm}sint32 Socket\+::set\+Attribute (
\begin{DoxyParamCaption}
\item[{sint32}]{attr, }
\item[{sint32}]{value}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily [virtual]}}}\label{class_socket_ae40a3069ac1e266adb1c4e9575190d49}


设置socket类型 


\begin{DoxyParams}{参数}
{\em socket\+Type} & S\+O\+C\+K\+E\+T\+\_\+\+T\+Y\+P\+E\+\_\+\+E \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
成功返回\+S\+T\+A\+T\+U\+S\+\_\+\+O\+K,失败返回\+S\+T\+A\+T\+U\+S\+\_\+\+E\+R\+R\+O\+R 
\end{DoxyReturn}
\begin{DoxyNote}{注解}
none 
\end{DoxyNote}


实现了 \hyperlink{class_i_o_device}{I\+O\+Device}.



该类的文档由以下文件生成\+:\begin{DoxyCompactItemize}
\item 
libemb/inc/\hyperlink{_socket_8h}{Socket.\+h}\item 
libemb/src/Socket.\+cpp\end{DoxyCompactItemize}
